#ifndef GAMETABLE_H
#define GAMETABLE_H

#include <QGraphicsObject>
#include <QDebug>
#include "gs.h"
using namespace gs;

namespace gs
{
class GameTable : public QGraphicsObject
{
    Q_OBJECT
public:
    GameTable(GameWindow*);
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    QList<Player*> getPlayerList();
    GameWindow* getGameWindow();
    InfoBoard * getInfoBoard();
    DeckBoard * getDeckBoard();
    Ghost* getDeckCurrentGhost();
    Player* getCurrentPlayer();
    Ghost* lastAllocatedGhost() { return nGhost; }
    ItemManager* getItemManager();
    QList<GhostBoard*> getGhostBoards();
    CenterTable* getCenterTable() {return cTable;}
    //table actions
    void check_ghost_action();
    void ghost_arrival();
    void taoist_act();
    void exo_act();
    void roll_curse_dice();
    //player update
    void updateCurrentPlayer(Player* pl);

    //facility functions for ghost skills
protected:
    void createPlayers();
    void setPlayerSkills();
    GameWindow* _window;
    QList<Player*> players;
    GamePhaseControl* phaseTable;
    CenterTable* cTable;
    LeftTable* lTable;
    RightTable* rTable;
    BottomTable* bTable;
    ItemManager* iManager;
private:
    Ghost * nGhost; // newly allocated ghost
signals:
    // see state transition signals:
    // https://docs.google.com/drawings/d/1uhTmtQukRy32ol64vrPiylCG8eSkUwPvAYvS2y06sL8/edit?hl=en_US
    void turn_finished();
    void exo_succ();
    void game_ended();
};

class ItemManager : public QObject
{
    Q_OBJECT
public:
    ItemManager(GameTable*);
    //get item methods
    QList<int> getRemainTaoNums();
    QList<int> getCurrentTaoNums();
    int getDiceNum();
    //set item methods
    void setRemainTaoNums(QList<int*>);
    void setDiceNum(int);

private:
    QList<Player*> plist;
    QList<int> RemainTaoNums;
    QList<int> CurrentTaoNums;
    int DiceNum;
    int defalut_TaoNum;

protected slots:
    void TaoNumUpdate();
};

}
#endif // GAMETABLE_H
